package com.youthfilmic.yuejian.controller.admin;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

/**
 * Created by youweixi on 15/10/12.
 */
@Controller
@RequestMapping("/admin")
public class LoginController {

    @RequestMapping("/login")
    public String showLogin(){
        return "admin/login";
    }

    @RequestMapping(value = "/login.do" , method = RequestMethod.POST)
    public String doLogin(
            @RequestParam("name") String name,
            @RequestParam("password") String password,
            HttpSession session
    ){
        if ("yuejian".equals(name) && "youthfilmic123".equals(password)){
            session.setAttribute("admin" , "true");
            return "redirect:/admin/index";
        }else{
            return "redirect:/admin/login?action=wrong";
        }
    }
}
